﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

public partial class Tailor_Measurement : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            loaddata();
        }
    }

    private void loaddata()
    {

        string sql = @"
SELECT [EmployeeID] as ID
      ,[EmployeeName] as Name 
,BranchID ,NoteDetails
  FROM Tailor_Employee 
order by BranchID,NoteDetails,[EmployeeName]

";

        DataSet ds = CommonManager.SQLExec(sql);
        gvItems.DataSource = ds.Tables[0];
        gvItems.DataBind();

      
    }

    protected void lbSelect_Click(object sender, EventArgs e)
    {
        LinkButton linkButton = new LinkButton();
        linkButton = (LinkButton)sender;
        
        string sql = @"
SELECT [EmployeeID] as ID
      ,[EmployeeName] as Name 
,BranchID,NoteDetails
  FROM Tailor_Employee  where [EmployeeID]=" + linkButton.CommandArgument;
        DataSet ds = CommonManager.SQLExec(sql);

        hfID.Value = ds.Tables[0].Rows[0][0].ToString();
        txtName.Text = ds.Tables[0].Rows[0][1].ToString();
        txtBranchNo.Text = ds.Tables[0].Rows[0][2].ToString();
        txtNote.Text = ds.Tables[0].Rows[0][3].ToString();
    }
    protected void lbDelete_Click(object sender, EventArgs e)
    {
        LinkButton linkButton = new LinkButton();
        linkButton = (LinkButton)sender;
        
        string sql = @"Delete [Tailor_Employee]   where [EmployeeID]=" + linkButton.CommandArgument;
         
        CommonManager.SQLExec(sql);
        loaddata();
        
    }

    protected void btnSave_Click(object sender, EventArgs e)
    {
        string sql="";
        if (hfID.Value == "")
        {
            sql = @"
INSERT INTO [Tailor_Employee]
           ([EmployeeName],BranchID,NoteDetails
           )
     VALUES(N'" + txtName.Text + @"'," + txtBranchNo.Text + @",N'" + txtNote.Text + @"')
";
        }
        else
        {
            sql = "update [Tailor_Employee] set [EmployeeName]=N'" + txtName.Text + @"',[NoteDetails]=N'" + txtNote.Text + @"',BranchID=" + txtBranchNo.Text + @"  where [EmployeeID]=" + hfID.Value;
            hfID.Value = "";
        }
        txtName.Text = "";
        txtNote.Text = "";
        txtBranchNo.Text = "";
        
        CommonManager.SQLExec(sql);
        loaddata();
    }
    protected void ddlItem_SelectedIndexChanged(object sender, EventArgs e)
    {
        loaddata();
    }
}